package club.caihappy.springsecuritydemo.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by DELL on 2022/5/8
 **/
@Controller
public class LoginController {
//
//    @RequestMapping("login")
//    public String login() {
//        System.out.println("执行登陆方法");
//        return "redirect:main.html";
//    }

//    @Secured("ROLE_abc")
    @PreAuthorize("hasAnyRole('abc')")
    @RequestMapping("toMain")
    public String toMain() {
        return "redirect:main.html";
    }

    @RequestMapping("toError")
    public String toError() {
        return "redirect:error.html";
    }

    @GetMapping("demo")
    @ResponseBody
    public String demo() {
        return "demo";
    }
}
